/**
 * Copyright (c) 2006-2012 Las Venturas Playground, LVP Mineground
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <http://www.gnu.org/licenses/>.
 */

package mineground.game.login;

import mineground.core.Message;
import mineground.core.MessageHandler;
import mineground.core.MessageLoopThread;
import mineground.core.ModuleControllerBase;
import mineground.entities.Player;
import mineground.entities.requests.LocationRunnable;
import mineground.util.Log;
import mineground.util.Vector3D;

/**
 * 
 * 
 * 
 * 
 */
public class Controller extends ModuleControllerBase {
    /**
     * 
     * 
     */
    @MessageHandler(message = Message.PlayerJoinEvent)
    public void onPlayerJoin(Player player) {
        player.sendMessage("Welcome on Las Venturas Mineground, " + player.getName() + "!");
        Log.notice("Player joined: %s", player.getName());
        
        // @TODO: Remove this message.
        final Player immutablePlayer = player;
        mMessageLoop.postDelayedTask(MessageLoopThread.GameThread, new Runnable() {
            public void run() {
                immutablePlayer.requestLocation(new LocationRunnable() {
                    public void run(Vector3D location, float pitch, float yaw) {
                        Log.notice("Position: %f %f %f", location.x, location.y, location.z);
                        immutablePlayer.sendMessage("Got your location!");
                    }
                });
            }
        }, 5000);
    }
    
    /**
     * 
     * 
     */
    @MessageHandler(message = Message.PlayerChatEvent)
    public void onPlayerChat(Player player, String message) {
        Log.notice("[%s] %s", player.getName(), message);
    }
    
    /**
     * 
     * 
     */
    @MessageHandler(message = Message.PlayerQuitEvent)
    public void onPlayerQuit(Player player, String message) {
        Log.notice("Player left: %s (%s)", player.getName(), message);
    }
}
